package com.twu.biblioteca.menuitems;

import com.twu.biblioteca.BibliotecaLibrary;
import com.twu.biblioteca.User;
import com.twu.biblioteca.menu.Menu;
import com.twu.biblioteca.menu.MenuItem;

/**
 * Created with IntelliJ IDEA.
 * User: ama
 * Date: 10/10/13
 * Time: 6:46 PM
 * This class understands how to
 * reserve a book from the library for a logged in user.
 */
public class ReserveABookMenuItem extends MenuItem {
    BibliotecaLibrary bibliotecaLibrary;

    public ReserveABookMenuItem(BibliotecaLibrary bibliotecaLibrary) {
        super("L2", "Reserve a book");
        this.bibliotecaLibrary = bibliotecaLibrary;
    }


    @Override
    public void runOption() {
        Menu.println("You need to be logged in to perform this action.");
        User loggedInUser = Menu.login();
        if (loggedInUser != null) {
            Menu.println("Enter title of book you wish to select and press ENTER.");
            Menu.println(bibliotecaLibrary.reserveBook(Menu.getInput()));
        } else {
            Menu.println("\nLogin failed.");
        }
    }
}
